#-*- coding: utf-8 -*-


def outer():
	free = 10
	
	def inner():
		print "inner: " + str( free )	# 印出自由變數free
		
	inner()			# 在outer()函式主體內，去呼叫並執行inner()內嵌函式
	
outer()				# 印出 10


def outerFunction():
	outerLocal = 100
	
	def innerFunciton():
		result = outerLocal + 100
		return "innerFunciotn: " + str( result )
	
	return innerFunciton

outerResult = outerFunction()
print "outerResult is: " + str( outerResult )

innerResult = outerResult()
print "innerResult is: " + str( innerResult )


def maker( n ):
	n += 30

	def action( x ):
		result = x + n
		return result
	
	return action
	
final = maker( 10 )( 20 )			# 比較怪異的呼叫方式
print "final is: " + str( final )	# 印出 60

action = maker( 10 )				# 把外層函式的回傳值指派給一個變數
result = action( 20 )
print "result is: " + str( result )	# 印出 60

anotherResult = action( 40 )
print "anotherResult is: " + str( anotherResult )	# 印出 80
